package com.rpoonolly.simplegame.mapio.jsoncoders;

import java.io.IOException;

import org.json.simple.JSONObject;

import com.rpoonolly.simplegame.animation.TexturedDynamicEntity;
import com.rpoonolly.simplegame.core.aabb.AABBEntity;

public class TexturedDynamicEntityJSONCoder extends JSONCoder<TexturedDynamicEntity> {
	private static TexturedDynamicEntityJSONCoder singletonInstance;
	private AABBEntityJSONCoder entCoder = AABBEntityJSONCoder.getInstance();

	private TexturedDynamicEntityJSONCoder() {}

	public static TexturedDynamicEntityJSONCoder getInstance() {
		if (singletonInstance == null) {
			singletonInstance = new TexturedDynamicEntityJSONCoder();
		}

		return singletonInstance;
	}

	@Override
	public JSONObject encode(TexturedDynamicEntity obj) throws IOException {
		return entCoder.encode(obj);
	}

	@Override
	public TexturedDynamicEntity decode(JSONObject code) throws IOException {
		AABBEntity ent = entCoder.decode(code);
		return new TexturedDynamicEntity(ent.getX(), ent.getY(), ent.getWidth(), ent.getHeight());
	}
}
